package com.proxy.common.codec.http;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpRequestDecoder;

import java.util.List;

/**
 * http 消息解码器
 */
public class MyHttpRequestDecoder extends HttpRequestDecoder{

//    private  Long sessionId;
    @Override
    public void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
        super.decode(ctx, buffer, out);
        /*for (Object o:out){
            if (o instanceof HttpRequest){
                 HttpRequest request= (HttpRequest) o;

                 if (request.headers().get(CommonConstant.SESSION_NAME)!=null){
                    System.out.println("==========已存在sessionId============");
                    return;
                 }
                 request.headers().add(CommonConstant.SESSION_NAME,sessionId);
            }
        }*/
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

      /*  ByteBuf buf= (ByteBuf) msg;
        ByteBuf buf2=buf.copy();

        byte[] bytes = new byte[buf2.readableBytes()];
        buf2.readBytes(bytes);
        String data = new String(bytes);
        System.out.println(data);
        if ((msg instanceof  ByteBuf)){
            if(buf.readableBytes()>=Long.BYTES){
                sessionId=buf.readLong();
             }

        }*/
        super.channelRead(ctx, msg);
    }

}
